package org.jeecg.modules.basic.report.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.basic.report.entity.GoodsReport;
import org.jeecg.modules.basic.report.entity.PersonReport;
import org.jeecg.modules.basic.report.service.GoodsReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * TODO
 *
 * @author sn
 * @date 2021-09-22 13:31
 */
@Api(tags="报修统计")
@RestController
@RequestMapping("/report/lwgyBxReport")
@Slf4j
public class GoodsReportController extends JeecgController<GoodsReport, GoodsReportService> {

    @Autowired
    private GoodsReportService goodsReportService;

    /**按照维修物品统计*/
    @PostMapping("/findGoodsReportList")
    @ResponseBody
    public Result<?>  findGoodsReportList(@RequestBody GoodsReport goodsReport){
        List<GoodsReport> reportList = goodsReportService.findGoodsReport(goodsReport);
        IPage<GoodsReport>reportIPage = new Page<GoodsReport>(0,100);

        for(int i=0;i<reportList.size();i++){
            GoodsReport goodsReport1 = reportList.get(i);
            String ids = goodsReport1.getIds();
            goodsReport1.setWxPlace(goodsReportService.findLhPlaceList(ids));
            goodsReport1.setWxPerson(goodsReportService.findPersonList(ids));
        }
        reportIPage.setRecords(reportList);
        return Result.OK(reportIPage);
    }

    /**按照维修人统计*/
    @PostMapping("/findPersonReportList")
    @ResponseBody
    public Result<?>  findPersonReportList(@RequestBody PersonReport personReport){
        List<PersonReport> reportList = goodsReportService.findPersonReport(personReport);
        IPage<PersonReport>reportIPage = new Page<PersonReport>(0,100);

        for(int i=0;i<reportList.size();i++){
            PersonReport personReport1 = reportList.get(i);
            String ids = personReport1.getIds();
            personReport1.setWxPlace(goodsReportService.findLhPlaceList(ids));
            personReport1.setWxGoods(goodsReportService.findGoodsList(ids));
        }
        reportIPage.setRecords(reportList);
        return Result.OK(reportIPage);
    }

}
